﻿using System.Data.Entity.ModelConfiguration;
using System.ComponentModel.DataAnnotations;

using Comswing.Business.Entities;

namespace Comswing.Data.Configuration
{
    internal class UserConfiguration : EntityTypeConfiguration<User>
    {
        public UserConfiguration()
        {
            HasKey(e => e.Id);

            Property(e => e.Id)
                .IsRequired()
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
                .HasColumnName("Id");

            Property(e => e.Account)
                .IsRequired()
                .IsUnicode(false)
                .HasMaxLength(60)
                .HasColumnName("Account");

            Property(e => e.Password)
                .IsRequired()
                .IsUnicode(false)
                .HasMaxLength(30)
                .HasColumnName("Password");

            Property(e => e.Email)
                .IsRequired()
                .IsUnicode(false)
                .HasMaxLength(30)
                .HasColumnName("Email");

            Property(e => e.IsLoggedin)
                .IsRequired()
                .HasColumnName("IsLoggedIn");

            Property(e => e.SignupDate)
                .IsRequired()
                .HasColumnName("SignupDate");

            HasRequired(e => e.Profile)
                .WithRequiredPrincipal();

            HasRequired(e => e.Organization)
                .WithRequiredPrincipal();

            HasMany(e => e.UserSwings)
                .WithRequired(r => r.User);

            HasMany(e => e.UserLogs)
                .WithRequired(r => r.User);

            ToTable("User", "dbo");
        }
    }
}
